using Glpt.Data;
using System;

namespace Glpt.Common
{
    /// <summary>
    /// MD5加密类
    /// </summary>
    public class MD5
    {
        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="txt">要加密的字符串</param>
        /// <returns>加密后字符串</returns>
        public static String Encrypt(String txt)
        {
            byte[] b = DataFuns.DefaultEncoding.GetBytes(txt);
            b = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(b);
            string ret = "";
            for (int i = 0; i < b.Length; i++)
            {
                ret += b[i].ToString("x").PadLeft(2, '0');
            }
            return ret;
        }

        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="txt">要加密的字符串</param>
        /// <returns>加密后字符串</returns>
        public static String Encrypt2(String txt)
        {
            return Encrypt(Encrypt(txt));
        }
    }
}
